/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package stack;

/**
 *
 * @author USER
 */
import java.util.ArrayList;

public class Stackarraylist<E>
 implements Stacki<E>
{
	protected ArrayList<E> data;

	public Stackarraylist()
	// post: constructs a new, empty stack
	{
		data = new ArrayList<E>();
	}

    @Override
	public void push(E item)
	// post: the value is added to the stack
	//          will be popped next if no intervening push
	{
		data.add(item);
	}

    @Override
	public E pop()
	// pre: stack is not empty
	// post: most recently pushed item is removed and returned
	{
		return data.remove(size()-1);
	}

    @Override
	public E peek()
	// pre: stack is not empty
	// post: top value (next to be popped) is returned
	{
		return data.get(size() - 1);
	}
	
    @Override
	public int size()
	// post: returns the number of elements in the stack
	{
		return data.size();
	}

    @Override
    public boolean empty() {
        return data.isEmpty();
    }
  
	
}
